import 'package:flutter/material.dart';
import 'my_change_notifier.dart';

//该类用于保存数据
//author:liuhaichao
class MyProvider<T extends MyChangeNotifier> extends InheritedWidget {
  const MyProvider({
    Key? key,
    required this.viewModel,
    required Widget child,
  }) : super(key: key, child: child);

  final T viewModel; //需要在子树中共享的数据

  //该回调决定当data发生变化时，是否通知子树中依赖data的Widget重新build
  @override
  bool updateShouldNotify(MyProvider oldWidget) {
    return viewModel.shouldNotify(oldWidget.viewModel);
  }
}
